#ifndef BARCODE_DETAIL_ALPHA_TO_DIGIT_HPP_INCLUDED
#define BARCODE_DETAIL_ALPHA_TO_DIGIT_HPP_INCLUDED

#include "../except.hpp"

#include <functional>
#include <locale>
#include <stdexcept>

namespace barcode { namespace detail {

template < typename CharType, typename OutputType >
struct alpha_to_digit
	: std::unary_function< CharType, OutputType >
{
	OutputType operator()( CharType char_ ) const
	{
		throw_if< not_a_digit >( !std::isdigit( char_, std::locale::classic() ) );

		return char_ - '0';
	}
};

}}

#endif //BARCODE_DETAIL_ALPHA_TO_DIGIT_HPP_INCLUDED
